package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PathVariable;
import sanrenxing.dayEnd.backRepertoryTotal.domain.SecuritiesInformation;

import java.util.List;
import java.util.Map;

/**
 * 功能：债券信息数据层接口类
 * 编写者：蒋玲苹
 * 日期：
 * 版本：1.0
 */

public interface SecuritiesInformationDao {
    /**
     * 添加数据
     * @param securitiesInformation
     * @return 0:添加失败,1:添加成功
     */
    @Insert("insert into securitiesInformation values(#{bondId},#{bondName},#{bondType},to_date('${beginInte}','yyyy-MM-dd'),to_date('${endInte}','yyyy-MM-dd'),#{coupRate},#{noipNum},#{parAmount})")
    public int add(SecuritiesInformation securitiesInformation);

    /**
     * 删除数据
     * @param bondId
     * @return 删除影响的行数(0:删除失败,1:删除成功)
     */
    @Delete("delete from securitiesInformation where bondId=#{bondId}")
    public int delete(@Param("bondId") String bondId);

    /**
     * 修改数据
     * @param securitiesInformation
     * @return 0:修改失败,1:修改成功
     */
    @Update("update securitiesInformation set bondId=#{bondId},bondName=#{bondName},bondType=#{bondType},beginInte=to_date('${beginInte}','yyyy-MM-dd'),endInte=to_date('${endInte}','yyyy-MM-dd'),coupRate=#{coupRate},noipNum=#{noipNum},parAmount=#{parAmount} where bondId=#{bondId}")
    public int update(SecuritiesInformation securitiesInformation);

    /**
     * 分页查询
     * @param map
     * @return
     */
    @Select("<script>" +
            "select bondId,bondName,bondType,to_char(beginInte,'yyyy-MM-dd') as beginInte,to_char(endInte,'yyyy-MM-dd') as endInte,coupRate,noipNum,parAmount from " +
            " (select rownum rn,securitiesInformation.* from securitiesInformation " +
            " <where>#{end}>=rownum</where>)" +
            "<where>" +
            "<if test='securitiesInformation.bondName!=null'>" +
            " and bondName like '%${securitiesInformation.bondName}%'" +
            "</if>" +
            "<if test='securitiesInformation.bondType!=null'>" +
            " and bondType like '%${securitiesInformation.bondType}%'" +
            "</if>" +
            " and rn>=#{start}" +
            "</where>" +
            "</script>")
    public List<SecuritiesInformation> queryAll(Map<String, Object> map);

    /**
     * 统计记录数
     * @return 记录行数据
     */
    @Select("select count(*) from securitiesInformation")
    public int count();

    /**
     * 添加证券信息
     */
    @Insert("insert into financialsecurities(seId,seName,seType,BreedRateId,issueDate,delayDate,stockId) " +
            "values(#{bondId},#{bondName},2,-1,to_date('${beginInte}','yyyy-MM-dd'),to_date('${delayDate}','yyyy-MM-dd')," +
            "-1)")
    public void addSec(@Param("bondId") String bondId,@Param("bondName") String bondName,@Param("beginInte") String beginInte,@Param("delayDate") String delayDate);

    /**
     * 删除债券数据方法
     * @param seId
     * @return 删除影响的行数(0:删除失败,1:删除成功)
     */
    @Delete("delete from financialsecurities where seId='${seId}'")
    public int deletes(@PathVariable("seId") String seId);

}
